package org.dromara.system.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.dromara.system.domain.SysProfitRule;
import org.dromara.system.domain.bo.SysProfitRuleBo;
import org.dromara.system.domain.query.SysProfitRuleQuery;
import org.dromara.system.domain.vo.SysProfitRuleVo;
import org.dromara.system.mapper.SysProfitRuleMapper;
import org.dromara.system.service.ISysProfitRuleService;

import java.util.Collection;
import java.util.List;

/**
 * 分佣规则Service业务层处理
 *
 * @author yixiacoco
 * @date 2025-09-04
 */
@Service
public class SysProfitRuleServiceImpl extends ServiceImpl<SysProfitRuleMapper, SysProfitRule> implements ISysProfitRuleService {

    /**
     * 查询分佣规则
     *
     * @param ruleId 主键
     * @return SysProfitRuleVo
     */
    @Override
    public SysProfitRuleVo queryById(String ruleId) {
        return baseMapper.selectVoById(ruleId);
    }

    /**
     * 分页查询分佣规则列表
     *
     * @param query 查询对象
     * @return 分佣规则分页列表
     */
    @Override
    public TableDataInfo<SysProfitRuleVo> queryPageList(SysProfitRuleQuery query) {
        return PageQuery.of(() -> baseMapper.queryList(query));
    }

    /**
     * 查询分佣规则列表
     *
     * @param query 查询对象
     * @return 分佣规则列表
     */
    @Override
    public List<SysProfitRuleVo> queryList(SysProfitRuleQuery query) {
        return baseMapper.queryList(query);
    }

    /**
     * 新增分佣规则
     *
     * @param bo 分佣规则新增业务对象
     * @return 是否新增成功
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(SysProfitRuleBo bo) {
        SysProfitRule add = MapstructUtils.convert(bo, SysProfitRule.class);
        return save(add);
    }

    /**
     * 修改分佣规则
     *
     * @param bo 分佣规则编辑业务对象
     * @return 是否修改成功
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByBo(SysProfitRuleBo bo) {
        SysProfitRule update = MapstructUtils.convert(bo, SysProfitRule.class);
        return updateById(update);
    }

    /**
     * 批量删除分佣规则信息
     *
     * @param ids 待删除的主键集合
     * @return 是否删除成功
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteWithValidByIds(Collection<String> ids) {
        return removeByIds(ids);
    }
}
